//
//  MineViewController.m
//  tangshantongjiAPP
//
//  Created by yuntai on 2018/4/3.
//  Copyright © 2018年 yuntai. All rights reserved.
//

#import "MineViewController.h"
#import "AboutUsViewController.h"
#import "ChangePassWordViewController.h"

@interface MineViewController ()<UITableViewDelegate,UITableViewDataSource>

@end

@implementation MineViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.title = @"我的";
    UILabel * subtitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, kNavigationHeight, kScreenBoundWidth, 50)];
    subtitleLabel.text =  [UserAccountManager shareUserAccountManager].userModel.trueName?:@"";
    subtitleLabel.textAlignment = NSTextAlignmentCenter;
    subtitleLabel.textColor = [UIColor whiteColor];
    subtitleLabel.font = [UIFont systemFontOfSize:16];
    subtitleLabel.backgroundColor = [UIColor colorWithRed:89/255.0 green:161/255.0 blue:220/255.0 alpha:1];
    [self.view addSubview:subtitleLabel];
    
    
    UITableView *tableview = [[UITableView alloc]initWithFrame:CGRectMake(0, 50+kNavigationHeight, kScreenBoundWidth, kScreenBoundHeight -kNavigationHeight-50)];
    tableview.delegate = self;
    tableview.dataSource = self;
    tableview.rowHeight = 50;
    tableview.bounces = NO;
    tableview.tableFooterView = [[UIView alloc]init];
    [self.view addSubview:tableview];
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 3;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    static NSString *cellID = @"mycellid";
    UITableViewCell *cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:cellID];
    [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator];
    [cell setSelectionStyle:UITableViewCellSelectionStyleNone];
    cell.textLabel.textColor = kTextDeepDarkColor;
    if (indexPath.row == 0) {
        cell.textLabel.text= @"修改密码";
        cell.imageView.image = [UIImage imageNamed:@"password"];
    }else if (indexPath.row == 1){
        cell.textLabel.text= @"关于我们";
        cell.imageView.image = [UIImage imageNamed:@"about"];

    }else{
        cell.textLabel.text= @"退出登录";
        cell.imageView.image = [UIImage imageNamed:@"loout"];

    }
    return cell;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.row == 0) {
        /**修改密码*/
        ChangePassWordViewController *vc =  [[UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle] ] instantiateViewControllerWithIdentifier:@"changepassVC"];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];

    }else if (indexPath.row == 1){
       /**关于我们*/
        AboutUsViewController *vc = [[AboutUsViewController alloc]init];
        vc.hidesBottomBarWhenPushed = YES;
        [self.navigationController pushViewController:vc animated:YES];
        
    }else{
        /**退出登录*/
        weakself(self)
        [AlertViewManager showAlertViewLogOutHandlerBlock:^{
            [weakself loginOutAction];
        }];
        
    }
    
}

- (void)loginOutAction{
    [HUDManager showLoadingHUDView:self.view];
    [NetWork PostNetWorkWithUrl:kUserLoginOutAction with:@{@"token":kTokenID} successBlock:^(NSDictionary *dic) {
        [[UserAccountManager shareUserAccountManager] logout];
    } FailureBlock:^(NSString *msg) {
        [[UserAccountManager shareUserAccountManager] logout];
    } errorBlock:^(id error) {
        [HUDManager showWarningWithText:@"退出失败!请重试!"];
    }];
}
@end
